﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.controllers.world {
    import flash.geom.*;
    import net.wooga.pets.events.*;
    import __AS3__.vec.*;
    import net.wooga.pets.models.world.vos.areas.*;
    import net.wooga.pets.interfaces.*;
    import net.wooga.pets.constants.*;

    public class MoveToRoomCommand extends AbstractMoveCommand {

        override public function execute():void{
            var _local5:IRoom;
            var _local6:Point;
            var _local8:Point;
            var _local9:Point;
            var _local10:IRoom;
            var _local11:int;
            var _local1:BuildingVO = world.building;
            var _local2:IAvatar = IAvatar(event.info);
            var _local3:String = _local2.targetRoomId;
            var _local4:Array = this.getRoute(_local2.roomId, _local3, _local1);
            var _local7:Vector.<Point> = new Vector.<Point>();
            if (_local4.length == 0){
                _local5 = (world.getRoomById(_local2.roomId) as IRoom);
                _local8 = _local5.getTargetPositionOf(_local2.state, _local2.targetX);
                _local9 = roomSlotsModel.getSlotById(_local5.slotId).position;
                _local6 = new Point((_local9.x + _local8.x), (_local9.y + _local8.y));
                _local7.push(_local6);
            } else {
                _local5 = getRoomBySlotId(_local4[0], _local1.rooms);
                _local10 = IRoom(getRoomBySlotId(_local4[(_local4.length - 1)], _local1.rooms));
                _local2.targetRoomId = _local10.id;
                _local2.nextRoomId = _local5.id;
                _local11 = IRoom(_local1.getRoom(_local2.roomId)).slotId;
                _local7 = getNextPosition(_local11, _local4[0]);
            };
            dispatch(new InfoEvent(EventConstants.MOVE_TO_POSITION, _local2.id, _local7));
        }
        private function getRoute(_arg1:String, _arg2:String, _arg3:BuildingVO):Array{
            var _local4:int = IRoom(_arg3.getRoom(_arg1)).slotId;
            var _local5:int = IRoom(_arg3.getRoom(_arg2)).slotId;
            var _local6:Array = roomSlotsModel.getRoute(_local4, _local5);
            return (_local6);
        }

    }
}//package net.wooga.pets.controllers.world 
